#ifndef JPGSTREAM_H
#define JPGSTREAM_H

#include <stdlib.h>
#include <iostream>
#include <istream>

#include <jpeglib.h>

class jpgstream {

  struct jpeg_decompress_struct dinfo;
  struct jpeg_compress_struct cinfo;
  struct jpeg_error_mgr jerr;

  int row_index;

public:

  struct jpg_info {
    int width;
    int height;
    int nc;
  } jpgheader;

  bool initializeInput(FILE *input);
  unsigned char *readLine();
  void finishInput();

  bool initializeOutput(FILE *output_file, int width, int height, int nc, int scale_num, int scale_denom);
  void write(unsigned char **data);
  void finishOutput();

  bool hasNext();

  jpgstream() : row_index(0) {};
};

#endif